package com.abluedog.event;

import com.abluedog.player.PlayerData;
import com.abluedog.state.BreakBlocksCountLoaderAndSaver;
import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;

public class CommandEvent {

    public static void register() {
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
                    dispatcher.register(literal("rsRecord").then(argument("player", EntityArgumentType.player())).executes(context -> {
                        ServerPlayerEntity player = context.getArgument("player", ServerPlayerEntity.class);
                        PlayerData playerData = BreakBlocksCountLoaderAndSaver.getPlayDate(player);
                        context.getSource().sendFeedback(() -> Text.literal("Total Break Blocks Count: " + playerData.getTotalBreakBlocksCount() + "\n"), false);
                        return 0;
                    }));
                }
        );
    }
}
